home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 297_01 / exampl11.spr < prev    next >
Text File  |  1980-01-01  |  1KB  |  49 lines

  1. /* exampl11.spr */
  2. /* loops again */
  3. /* here are two ways of doing loops
  4.    They are not equivalent.
  5.  */
  6.  
  7. /* enum gives you a sort of an equivalent of a for loop 
  8.  through bactracking and recursion
  9.  your are expected to supply the first three arguments
  10.  as well as the fifth.
  11.  */
  12.  
  13. ((enum Initial Step Final Initial Execute_me)
  14.  (ileq Initial Final)
  15.  Execute_me
  16. )
  17. ((enum Initial Step Final Initial Execute_me)
  18.  (iless Final Initial)
  19.  (cut)
  20. )
  21. ((enum Intermediate Step Final Value Execute_me)
  22.  (iplus Intermediate Step Intermediate2)
  23.  (enum Intermediate2 Step Final Value Execute_me)
  24. )
  25.  
  26. /* recursive_loop works via pure recursion instead */
  27. ((recursive_loop Initial Step Final Execute_me)
  28.  (iless Initial Final)
  29.  (cut)
  30.  Execute_me
  31.  (iplus Initial Step Initial2)
  32.  (enum Initial2 Step Final Execute_me)
  33. )
  34. (recursive_loop _ _ _)
  35.  
  36. ((demo11)
  37.  (enum 1 1 10 Value (display Value))
  38.  (fail)
  39. )
  40. (demo11)
  41.  
  42. /* You can't abstract out a variable for a loop using
  43.    recursive loop because one a prolog variable has a value
  44.    it can only lose it through backtracking 
  45.    Nevertheless you can always solve loop problems
  46.    without bactracking. For example the sum predicate 
  47.    in sprolog.ini.
  48.  */
  49.